let clearBtn = document.querySelectorAll('.main .clear');
let inputArr = document.querySelectorAll('.main .put');
console.log(clearBtn);
console.log(inputArr);

clearBtn.forEach(function (v, i) {
    v.onclick = function () {
        inputArr[i].value = '';
        v.style.display = 'none';
    }
})

inputArr.forEach(function (v, i) {
    v.oninput = function () {
        if (v.value.length >= 1) {
            clearBtn[i].style.display = 'block'
        } else {
            clearBtn[i].style.display = 'none'
        }
    }
})

let count = document.querySelector('.tel button');
console.log(count);

count.onclick = function () {
    let a = 60;
   let timer= setInterval(() => {
        count.innerHTML = a--
    }, 1000);
    if(a<=0){
        clearInterval(timer);
    }
}


/*注册正则*/
let regArr = [
    /^[a-zA-Z]\w{5,11}$/,   //6-12: 字母开头,后面跟字母\数字\下划线
    /^1[3456789][0-9]{9}$/, //11  : 
    /^[a-zA-Z]\w{3}$/,      //4位验证码: 字母开头,后面跟字母\数字\下划线
    /^[a-zA-Z]\w{5,11}$/    //6-12: 字母开头,后面跟字母\数字\下划线
]

//警告数组
let warnArr=document.querySelectorAll('.warning');
//先给input写失去焦点事件
inputArr.forEach(function(v,i){
    v.onblur=function(){
        if(regArr[i].test(v.value)==false){
            //显示警告文字
            warnArr[i].style.display='block'
        }else{
            //隐藏警告文字
            warnArr[i].style.display='none'
        }
    }
})

let accept = document.querySelector('.accept');
let sign = document.querySelector('.sign button');
accept.onclick = function () {
    if(this.checked){
        sign.classList.add('on');
        sign.disabled = false;
    }else{
        sign.classList.remove('on');
        sign.disabled = true;
    }
}

//注册按钮
sign.onclick=function(){
    let flag = true;//标杆：假设所有内容为true，flag就为true
    //再次验证(同时验证4个信息)
    inputArr.forEach(function(v,i){
        if(regArr[i].test(v.value)){
            warnArr[i].style.display='none'
        }else{
            warnArr[i].style.display='block'
            flag = false;
        }
    })
    console.log(flag);
}




  


